<template>
  <footer class="footer">
    <span class="todo-count"
      >剩余<strong>{{ unDoneTodoLength }}</strong></span
    >
    <ul class="filters">
      <li>
        <a
          :class="{ selected: type === 'all' }"
          @click="type = 'all'"
          href="javascript:;"
          >全部</a
        >
      </li>
      <li>
        <a
          href="javascript:;"
          :class="{ selected: type === 'no' }"
          @click="type = 'no'"
          >未完成</a
        >
      </li>
      <li>
        <a
          href="javascript:;"
          :class="{ selected: type === 'yes' }"
          @click="type = 'yes'"
          >已完成</a
        >
      </li>
    </ul>
    <button class="clear-completed" v-if="hasDoneTodo" @click="clearDoneTodo">
      清除已完成
    </button>
  </footer>
</template>

<script>
export default {
  props: ["list"],
  data() {
    return {
      type: "all", //自定义规则 用来更改选中状态添加选中样式
    };
  },
  computed: {
    unDoneTodoLength() {
      return this.list.filter((item) => item.isDone === false).length;
    },
    hasDoneTodo() {
      return this.list.some((item) => item.isDone === true);
    },
  },
  methods: {
    clearDoneTodo() {
      if (window.confirm("是否清除")) {
        this.$emit("clear-Todo");
      }
    },
  },
};
</script>